<?php

/*
 * 商品控制器
 * @author sky
 * create_time 2017-03-26
 */


namespace App\Admin\Controllers\Goods;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\Constraint;
use Intervention\Image\Facades\Image;
use App\Admin\Controllers\Controller;
use App\Admin\Models\Logs;
use App\Admin\Models\UploadImg;
use App\Admin\Models\Menber;

class MenberController extends Controller {


    /*
     * 编辑添加会员
     * @author sky
     * create_time 2017-03-26
     */
    // 添加会员
    public function usersAdd(Request $request) {
        if ($request->isMethod('get')) {
            return view('admin.users');
        } elseif ($request->isMethod('post')) {
            $image = $request->file('images');
            $data = UploadImg::upload($image, 'users');
            $addusers = array(
            'name' => $request['name'],
            'passworld' => $request['passworld'],
            'nick' => $request['nick'],
            'num' => $request['num'],
            'img' => $data
        );
            users::addusers($addusers);
             return view('admin.users');
        }
    }
    // 商品列表
    public function userList(Request $request) {
        // $users = users::usersList();
        // $datas['users'] = $users;
        return view('admin.menber');
    }
     // 删除商品
    public function usersDeleted(Request $request){
        $id=$request->get('id');
        $res = users::usersDeleted($id);
        if($res) {
            return "true";
        }else {
            return "false";
        }
        // return view('admin.userslist');
    }

    // 商品详情
     public function usersDetails(Request $request){
        $id=$request->get('id');
        $details = users::usersDetail($id);
        $data['details'] = $details;
        return view('admin.detail',$data);
    }
    // 修改商品
     public function usersUpdates(Request $request){
        if ($request->isMethod('get')) {
            $id=$request->get('id');
            $details = users::usersDetail($id);
            $data['details'] = $details;
            return view('admin.updates',$data);
        } elseif ($request->isMethod('post')) {
            $up_id = $request['id'];
            $addusers = array(
            'name' => $request['name'],
            'cost' => $request['price'],
            'descript' => $request['descript'],
            'num' => $request['num']
        );
            users::usersUpdate($up_id,$addusers);
            return redirect()->route('users.list');

        }
    }
}
